package com.itheima.day13.Zuoye.ZuoYe2;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Mythread extends  Thread{
    private List<Integer> x;
    private List<Integer> t1count = new ArrayList<>();
    private List<Integer> t2count = new ArrayList<>();

    public List<Integer> getT1count() {
        return t1count;
    }

    public List<Integer> getT2count() {
        return t2count;
    }


    public Mythread(String name, List<Integer> x) {
        super(name);
        this.x = x;
    }
    @Override
    public void run() {
        Thread thread = Thread.currentThread();
            Random random = new Random();
        while (true) {
            synchronized (x) { if(x.size()==0){
                System.out.println("抽奖完毕");
                return;
            }
            int i = random.nextInt(x.size());
            System.out.println(getName()+"正在抽奖,金额为："+x.get(i));
            int price = x.get(i);
            x.remove(i);
            if(thread.getName().equals("t1")){
                t1count.add(price);
            }else{
                t2count.add(price);
            }}
            try {
                thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }

        }

    }
}
